home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 1833 / 1833.xpi / modules / yoonoUtils.js < prev    next >
Text File  |  2009-12-16  |  6KB  |  179 lines

  1. var EXPORTED_SYMBOLS = ["YOONO_UTILS"];
  2.  
  3. // Vars
  4. const YOONO_ID = "{d9284e50-81fc-11da-a72b-0800200c9a66}";
  5. const MAGIC_URL = 'about:blank';
  6.  
  7.  
  8. // Globals
  9. const CI = Components.interfaces;
  10. const CL = Components.classes;
  11. const DIRSERVICE = CL['@mozilla.org/file/directory_service;1'].getService(CI.nsIProperties);
  12. const PREFBRANCH = CL['@mozilla.org/preferences-service;1'].getService(CI.nsIPrefBranch);
  13. const PREFSSERVICE = CL["@mozilla.org/preferences-service;1"].getService(CI.nsIPrefService);
  14. const PREFS = PREFSSERVICE.getBranch("extensions.yoono.");
  15. const RDF = CL["@mozilla.org/rdf/rdf-service;1"].getService(CI.nsIRDFService);
  16.  
  17. const URL_RESOURCE            = RDF.GetResource("http://home.netscape.com/NC-rdf#URL");
  18. const FEED_URL_RESOURCE       = RDF.GetResource("http://home.netscape.com/NC-rdf#FeedURL");
  19.  
  20. const LIVEBKM_TYPE   = "http://home.netscape.com/NC-rdf#Livemark";
  21. const LIVETAG = '.LIV';
  22.  
  23.  
  24. function Utils() {
  25.     this.wrappedJSObject=this;
  26.         
  27. }
  28.  
  29. Utils.prototype.getExtensionVersion = function () {
  30.     var extmgr = CL['@mozilla.org/extensions/manager;1'].getService(CI.nsIExtensionManager);
  31.     return extmgr.getItemForID(YOONO_ID).version;
  32. }
  33. Utils.prototype.getUserAgent = function (win) {
  34.     return(win.navigator.userAgent.toLowerCase());
  35. }
  36. Utils.prototype.getUserAgentAppVersion = function (win) {
  37.     return(win.navigator.appVersion.toLowerCase());
  38. }
  39. Utils.prototype.getUserAgentOsCpu = function (win) {
  40.     return(win.navigator.oscpu.toLowerCase());
  41. }
  42. Utils.prototype.getUserAgentPlatform = function (win) {
  43.     return(win.navigator.platform.toLowerCase());
  44. }
  45. Utils.prototype.getLocale = function () {
  46.     return (PREFBRANCH.getCharPref('general.useragent.locale'));
  47. }
  48.  
  49. Utils.prototype.stringException = function (e) {
  50.     return(e.toString);
  51. }
  52.  
  53. // Return general debug info
  54. Utils.prototype.dumpDebugInfo = function() {
  55.     var aDebugInfo = '################################################################################\n';
  56.  
  57.     var appInfo = CL["@mozilla.org/xre/app-info;1"].getService(CI.nsIXULAppInfo);
  58.     aDebugInfo = aDebugInfo+'firefox version                 : '+appInfo.version+'\n';
  59.     aDebugInfo = aDebugInfo+'firefox build id                : '+appInfo.appBuildID+'\n';
  60.     aDebugInfo = aDebugInfo+'yoono extension version         : '+this.getExtensionVersion()+'\n';
  61.     aDebugInfo = aDebugInfo+'general.useragent.extra.firefox : '+PREFBRANCH.getCharPref('general.useragent.extra.firefox')+'\n';
  62.     aDebugInfo = aDebugInfo+'general.useragent.locale        : '+PREFBRANCH.getCharPref('general.useragent.locale')+'\n';
  63.     aDebugInfo = aDebugInfo+'intl.accept_languages           : '+PREFBRANCH.getCharPref('intl.accept_languages')+'\n';
  64.  
  65.     // Affiche le chemin du rΘpertoire profile
  66.     aDebugInfo = aDebugInfo+'Profile directory               : '+DIRSERVICE.get("ProfD",CI.nsIFile).path+'\n';
  67.  
  68.     // Liste les prΘfΘrences yoono
  69.     aDebugInfo = aDebugInfo+'\nYoono preferences :\n';
  70.     var yoonoPrefChildren = PREFS.getChildList("", {});
  71.     for(var i in yoonoPrefChildren) {
  72.     if (yoonoPrefChildren[i] == "userid"){
  73.       aDebugInfo = aDebugInfo+'extensions.yoono.'+yoonoPrefChildren[i]+' : **********************\n';
  74.     }
  75.     else {
  76.       switch(PREFBRANCH.getPrefType('extensions.yoono.'+yoonoPrefChildren[i])) {
  77.       case CI.nsIPrefBranch.PREF_STRING: // PREF_STRING = 32
  78.         aDebugInfo = aDebugInfo+'extensions.yoono.'+yoonoPrefChildren[i]+' : '+PREFBRANCH.getCharPref('extensions.yoono.'+yoonoPrefChildren[i])+'\n';
  79.         break;
  80.       case CI.nsIPrefBranch.PREF_INT: // PREF_INT    = 64
  81.         aDebugInfo = aDebugInfo+'extensions.yoono.'+yoonoPrefChildren[i]+' : '+PREFBRANCH.getIntPref('extensions.yoono.'+yoonoPrefChildren[i])+'\n';
  82.         break;
  83.       case CI.nsIPrefBranch.PREF_BOOL: // PREF_BOOL    = 128
  84.         aDebugInfo = aDebugInfo+'extensions.yoono.'+yoonoPrefChildren[i]+' : '+PREFBRANCH.getBoolPref('extensions.yoono.'+yoonoPrefChildren[i])+'\n';
  85.         break;
  86.       }
  87.     }
  88.   }
  89.  
  90.     // Liste les extensions installΘes
  91.     aDebugInfo = aDebugInfo+'\nFirefox extensions :\n';
  92.     var aExtManager = CL["@mozilla.org/extensions/manager;1"].getService(CI.nsIExtensionManager);
  93.     var aItemList = aExtManager.getItemList(CI.nsIUpdateItem.TYPE_ANY, { });
  94.     for(var i in aItemList) {
  95.         aDebugInfo = aDebugInfo+aItemList[i].name+', version='+aItemList[i].version+', update-url='+aItemList[i].updateRDF+'\n';
  96.     }
  97.  
  98.     aDebugInfo = aDebugInfo+'################################################################################\n';
  99.     return aDebugInfo;
  100. }
  101.  
  102.  
  103.  
  104. /*
  105.     @param str : une chaine qui represente le chemin
  106.     @return list : une liste qui represente le chemin
  107.     les chemins dans la chaine sont separes par des slash
  108.     les slashs qui font partie du nom de la chaine sont echappes
  109.     cela correspond a  split(/(?!\\)\//)
  110.     qui semble ne pas marcher en javascript
  111.     ensuite, on desechappe les slash
  112. */
  113. Utils.prototype.splitPath = function (str) {
  114.     // supprime le dernier caractere si c'est un '/' non precede d'un '\'
  115.     if (str.length != 1 && str[str.length - 1] == '/' && str[str.length - 2] != '\\') {
  116.         str = str.slice(0, -1);
  117.     }
  118.  
  119.     var list = new Array();
  120.     var lastpos = 0;
  121.     var extract = '';
  122.     var l = str.length;
  123.     for (var pos = 0 ; pos <= l ; pos++) {
  124.         if ((str[pos] == '/' && str[pos - 1] != '\\') || pos == l) {
  125.             extract = str.slice(lastpos + 1,pos);
  126.             extract = extract.replace(/\\(\\|\/)/g,'$1');
  127.             list.push(extract);
  128.             lastpos = pos;
  129.         }
  130.     }
  131.  
  132.     return list;
  133. }
  134.  
  135. Utils.prototype.normalize = function (str) {
  136.     if (!str)
  137.         return str;
  138.     str = this.replaceIEInvalids(str);
  139.     str = str.replace(/[\s\.]*$/,'');
  140.     return str;
  141. }
  142.  
  143. Utils.prototype.escapePath = function(name) {
  144.     if (!name) return '';
  145.     name = name.replace(/\\/g, '\\\\');
  146.     name = name.replace(/\//g, '\\/');
  147.     return name;
  148. }
  149.  
  150. Utils.prototype.replaceIEInvalids = function (attribute) {
  151.     if (!attribute) return '';
  152.     attribute = attribute.replace(/\\|:|\*|\?|"|<|>|\|/g,'');
  153.     attribute = attribute.replace(/\//g, '-');
  154.     return attribute;
  155. }
  156.  
  157. /*
  158.     @param list : une liste ou un objet
  159.     @return obj : une copie de la liste ou de l'objet
  160. */
  161. Utils.prototype.copyObjectOrArray = function (list) {
  162.     // point final de la recursion
  163.     if (typeof list != 'object')
  164.         return list;
  165.  
  166.     if (list.length === undefined)
  167.         var obj = new Object();
  168.     else
  169.         var obj = new Array();
  170.  
  171.     for (var i in list)
  172.         obj[i] = this.copyObjectOrArray(list[i]);
  173.  
  174.     return obj;
  175. }
  176.  
  177.  
  178. var YOONO_UTILS = new Utils();
  179.